package com.shudingke.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shudingke.domain.Orderitem;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-06-29
 */
@Controller
@RequestMapping("/orderitem")
public class OrderitemController {

    @RequestMapping("/load")
    @ResponseBody
    public Map load(HttpServletRequest req){
        Map map = new HashMap();
        int itemId = (Integer) req.getSession().getAttribute("itemId");
        Orderitem orderitem = new Orderitem();
        QueryWrapper<Orderitem> qw = new QueryWrapper<>();
        qw.eq("id",itemId);
        List<Orderitem> list = orderitem.selectList(qw);
        double price = 0;
        for (Orderitem orderitem1 : list) {
            price += orderitem1.getPrice() * orderitem1.getNum();
        }
        map.put("itemId",itemId);
        map.put("price",price);
        return map;
    }
    
    
    @RequestMapping("/confirmPay")
    @ResponseBody
    public int confirmPay(){
        return 200;
    }
    
    
    @RequestMapping("/goSuccess")
    public String goSuccess(){
        return "paySuccess";
    }

    @RequestMapping("/goFail")
    public String goFail(){
        return "payFail";
    }
}

